<template>
    <div id="printMe" class="jurisdiction">
        <el-row style="text-align: right;margin: 10px 0px;">
            <el-col>
                <el-button type="success" @click="add">新建用户</el-button>
                <el-select
                    style="width:200px"
                    @change="changePerson"
                    size="small"
                    v-model="personKind"
                    filterable
                    remote
                    reserve-keyword
                    placeholder="请输入关键词"
                    :remote-method="remoteProviderMethod"
                >
                    <el-option
                        size="small"
                        v-for="item in managementUserKind"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"
                    ></el-option>
                </el-select>
            </el-col>
        </el-row>
        <el-row>
            <el-table  :data="roleData" style="width: 100%" border>
                <el-table-column type="index" label="序号" width="200" align="center" :index="indexSort">
                </el-table-column>
                <el-table-column prop="userId" label="用户唯一id" align="center">
                </el-table-column>
                <el-table-column prop="account" label="账号" align="center">
                </el-table-column>
                <el-table-column prop="age" label="年龄" align="center">
                </el-table-column> 
                <el-table-column prop="maximg" label="头像" align="center">
                    <template slot-scope="scope">
                        <img :src="scope.row.maximg" alt="">
                    </template>
                </el-table-column> 
                <el-table-column prop="sex" label="性别" align="center">
                </el-table-column>
                <el-table-column prop="mobile" label="手机号" align="center">
                </el-table-column>
                <el-table-column prop="idCard" label="身份证号" align="center">
                </el-table-column>
                <el-table-column prop="updateDate" label="更新时间" align="center">
                </el-table-column>
                <el-table-column label="操作" align="center" width="200">
                    <template slot-scope="scope">
                        <el-button type="text" style="cursor: pointer;" @click="deleteRow(scope.$index ,scope.row.shTypeId, houseCats)" size="mini">
                        删除
                        </el-button>
                        <el-button type="text" style="cursor: pointer;" @click="updateRow(scope.row)" size="mini">
                        编辑
                        </el-button>
                        <el-button type="text" style="cursor: pointer;" @click="roleDetail(scope.row)" size="mini">
                        角色
                        </el-button>
                        <el-button type="text" style="cursor: pointer;" @click="addressDetail(scope.row)" size="mini">
                        用户地址
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-row>
        <el-row style="text-align: right;">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[15, 50, 100, 200]"
                :page-size="pageSize"
                layout="->, sizes, prev, pager, next, jumper, total"
                :total="totalElements"
            ></el-pagination>
        </el-row>
        <add :off.sync="addRoleDialog"></add>
        <edit :rowData="rowData" :off.sync="userDetailDialog"></edit>
        <role :rowData="rowData" :off.sync="roleDetailDialog"></role>
        <address2 :off.sync="addressDetailDialog"></address2>
    </div>    
</template>

<script>
    import { getAdminList } from "@/api/admin.js"
    import { excel } from "@/util/excel.js"
    import * as util from "@/util/util.js"
    export default {
        name: "jurisdiction",
        components: {
           "add": () => import("./add.vue"),
           "edit": () => import("./edit.vue"),
           "role": () => import("./role.vue"),
           "address2": () => import("./address2.vue")
        },
        data(){
            return {
                rowData: {},
                personKind: "",
                managementUserKind: [
                    {label: "商超管理员", value: "2"},
                    {label: "农资管理员", value: "3"},
                ],
                userDetailDialog: false,
                addRoleDialog: false,
                roleDetailDialog: false,
                addressDetailDialog: false,
                pageSize: 15,
                currentPage: 1,
                totalElements: 0,
                totalPages: 1,
                roleData:[
                    
                ]
            }
        },
        mounted(){
           
        },
        created(){
            this.getList();
        },
        methods: {
            remoteProviderMethod(){},
            changePerson(){
                this.getList();
            },
            formatDate(now) { 
                var year = now.getFullYear();  //取得4位数的年份
                var month = now.getMonth()+1;  //取得日期中的月份，其中0表示1月，11表示12月
                var date = now.getDate();      //返回日期月份中的天数（1到31）
                var hour = now.getHours();     //返回日期中的小时数（0到23）
                var minute = now.getMinutes(); //返回日期中的分钟数（0到59）
                var second = now.getSeconds(); //返回日期中的秒数（0到59）
                return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second; 
            },
            add(){
                this.addRoleDialog = true;
            },
            roleDetail(row){
                this.rowData = row;
                this.roleDetailDialog = true;
            },
            addressDetail(){
                console.log("--------");
                this.addressDetailDialog = true;
            },
            getList(){
                getAdminList({
                    currentPage: this.currentPage,
                    pageSize: this.pageSize,
                    total: 10,
                    type: this.personKind ? this.personKind : 2
                }).then(
                    res => {
                        console.log("res权限接口", res);
                        this.roleData = res.data.list;
                        this.roleData.forEach((e) => {
                            // http://image.xynph.com/1557912457560.jpg
                            // e.updateDate = String(e.updateDate).replace("/0{3}$/", " ");
                            e.updateDate = util.timestampToTime(e.updateDate);
                            e.maximg = "http://image.xynph.com/" + e.mobile + ".jpg";
                            if(e.sex == 1){
                                e.sex = "男";
                            }else{
                                e.sex = "女";
                            }
                        });
                        this.totalElements = res.data.total;
                    },
                    err => {}
                );
            },
            deleteRow(){

            },
            updateRow(row){
                console.log("row", row);
                this.userDetailDialog = true;
                this.rowData = row;
            },
            //序号
            indexSort(index) {
                if (this.currentPage > 1) {
                    index = (this.currentPage - 1) * this.pageSize + index + 1;
                } else {
                    index = index + 1;
                }
                return index;
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.getList();
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                this.currentPage = val;
                this.getList();
                console.log(`当前页: ${val}`);
            }
        }
    }
</script>

<style lang="less">
.jurisdiction{
    
}
</style>